package networkProgramming.UDP;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;


public class UDPReceive {
    public static void main(String[] args) throws IOException {
        DatagramSocket ds = new DatagramSocket(10086);
        byte[] bytes = new byte[1024];
        DatagramPacket datagramPacket = new DatagramPacket(bytes, bytes.length);
        ds.receive(datagramPacket);
        byte[] data = datagramPacket.getData();
        int len = datagramPacket.getLength();
        InetAddress address = datagramPacket.getAddress();
        int port = datagramPacket.getPort();
        System.out.println("接收数据" + new String(data, 0, len));
        System.out.println("该数据是从" + address + "这台电脑中的" + port + "端口发出的");
        ds.close();


    }
}
